package com.coderman.common.starter.tianqing.qlexpress.listener;

import com.coderman.common.starter.tianqing.qlexpress.config.NacosQlExpressProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * Description:
 * date: 2020/10/14
 *
 * @author fanchunshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Order(value = 1002)
@Component
public class SpringQlExpressConfigListener  implements ApplicationListener<ApplicationStartedEvent> {
    private Logger logger = LoggerFactory.getLogger(SpringQlExpressConfigListener.class);

    @Autowired
    private QlExpressConfigListener iListener;

    @Autowired
    private NacosQlExpressProperties nacosQlExpressProperties;

    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        try {
            logger.info("应用启动成功,准备初始化业务配置数据:TianQing-QlExpress.......................");
            iListener.addListener(nacosQlExpressProperties.getDataIDArr(),nacosQlExpressProperties.getGroupIDArr());
            logger.info("应用启动成功,初始化业务配置数据成功:TianQing-QlExpress.......................");

        } catch (Exception e) {
            logger.error("初始化远程配置失败:TianQing-QlExpress",e);
        }

    }
}
